package com.android.telephonecall.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * Android 工具
 */
public class AndroidUtils {

    /**
     * 获取版本号
     *
     * @return 应用版本号
     */
    public static String getAppVersion(Context context) {
        try {
            PackageManager pm = context.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
            return pi.versionName;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 获取13长度时间戳
     * @return 13长度时间戳
     */
    public static String getTimeStamp() {
        long timestamp = System.currentTimeMillis();
        String timestampString = String.valueOf(timestamp);
        if (timestampString.length() > 13) {
            timestampString = timestampString.substring(0, 13);
        } else if (timestampString.length() < 13) {
            int diff = 13 - timestampString.length();
            for (int i = 0; i < diff; i++) {
                timestampString = "0" + timestampString;
            }
        }
        return timestampString;
    }

}
